package com.yanqu.road.entity.activity.witchdraw.config;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WitchDrawConfig {
    //积分
    private int scoreItemId;
    //抽取消耗道具
    private int drawItemId;
    //兑换道具1
    private int tokenItem1;
    //兑换道具2
    private int tokenItem2;
    //兑换道具3
    private int tokenItem3;
    //单次抽取获得的积分
    private int drawScore;
    //无双召唤保底最小值
    private int drawSimpleEnsureSmallestParam;
    //无双召唤保底最大值
    private int drawSimpleEnsureBiggestParam;
    //神话召唤保底最小值
    private int drawMythEnsureSmallestParam;
    //神话召唤保底最大值
    private int drawMythEnsureBiggestParam;

    //神话召唤奖励免费抽数
    private int drawMythFreeTimes;
    //解锁十连召唤和跳过动画的条件
    private int tenDrawUnlockParam;

    //防止玩家不充钱还白嫖 积分获得小于等于该数量的时候出神话的次数需要限制 比如60次道具使用的 3000积分的时候
    private int drawMythLimitMythDrawScore;

    //防止玩家不充钱还白嫖 积分获得少于上面那个数量时限制多少次数 比如2
    private int drawMythLimitMythDrawTimes;


    private Map<Integer,WitchDrawCombConfig> combConfigMap;

    private Map<Integer,WitchDrawItemConfig> drawItemConfigMap;

    private Map<Integer,Integer> drawCombWeightMap;

    private Map<Integer,Map<Integer,Integer>> floatWeightMap;

    public WitchDrawConfig(Map<Integer, WitchDrawCombConfig> combConfigMap,
                           Map<Integer, WitchDrawItemConfig> drawItemConfigMap,
                           Map<String, ActivityConfig> activityConfigMap) {
        this.combConfigMap = combConfigMap;
        this.drawItemConfigMap = drawItemConfigMap;
        this.scoreItemId = activityConfigMap.get("EXCHANGE_SCORE_ITEM_ID").getIntValue();
        this.drawItemId = activityConfigMap.get("WITCH_ENERGY_ITEM_ID").getIntValue();
        this.tokenItem1 = activityConfigMap.get("WITCH_TOKEN_ID_1").getIntValue();
        this.tokenItem2 = activityConfigMap.get("WITCH_TOKEN_ID_2").getIntValue();
        this.tokenItem3 = activityConfigMap.get("WITCH_TOKEN_ID_3").getIntValue();
        this.drawScore = activityConfigMap.get("WITCH_ACHIEVE_SCORE_ITEM_NUMBER").getIntValue();
        String simpleEnsureString = activityConfigMap.get("WITCH_UNMATCHED_SUMMON_PARAM").getValue();
        List<Integer> simpleEnsureList = StringUtils.stringToIntegerList(simpleEnsureString, ";");
        this.drawSimpleEnsureSmallestParam = simpleEnsureList.get(0);
        this.drawSimpleEnsureBiggestParam = simpleEnsureList.get(1);
        String mythEnsureString = activityConfigMap.get("WITCH_BUFF_FREE_TIMES_PARAM").getValue();
        List<Integer> mythEnsureList = StringUtils.stringToIntegerList(mythEnsureString, ";");
        this.drawMythEnsureSmallestParam = mythEnsureList.get(0);
        this.drawMythEnsureBiggestParam = mythEnsureList.get(1);

        this.drawMythFreeTimes = activityConfigMap.get("WITCH_BUFF_FREE_TIMES").getIntValue();
        this.drawCombWeightMap = new ConcurrentHashMap<>();
        this.floatWeightMap = new ConcurrentHashMap<>();
        for (WitchDrawCombConfig combConfig : combConfigMap.values()) {
            drawCombWeightMap.put(combConfig.getId(),combConfig.getWeight());
            //不为0才需要浮动
            String floatWeight = combConfig.getFloatWeight();
            if (!StringUtils.isNullOrEmpty(floatWeight) && !floatWeight.equals("0")){
                List<String> strings = StringUtils.stringToStringList(floatWeight, "\\|");
                if (strings.isEmpty()||strings.size()<2){
                    continue;
                }
                Map<Integer,Integer> floatMap = new ConcurrentHashMap<>();
                for (String s:strings){
                    List<Integer> integerList = StringUtils.stringToIntegerList(s, ",");
                    if (integerList.size() == 2){
                        floatMap.put(integerList.get(0),integerList.get(1));
                    }
                }
                if (!floatMap.isEmpty()){
                    floatWeightMap.put(combConfig.getId(),floatMap);
                }
            }

        }

        this.tenDrawUnlockParam = activityConfigMap.get("WITCH_TEN_GACHA_OPEN").getIntValue();

        if (activityConfigMap.containsKey("WITCH_BUFF_FREE_TIMES_LIMIT")){
            List<Integer> witchBuffFreeTimesLimit = activityConfigMap.get("WITCH_BUFF_FREE_TIMES_LIMIT").getIntListValue(";");
            if (witchBuffFreeTimesLimit.size() == 2){
                this.drawMythLimitMythDrawScore = witchBuffFreeTimesLimit.get(0);
                this.drawMythLimitMythDrawTimes = witchBuffFreeTimesLimit.get(1);
            }else {
                this.drawMythLimitMythDrawScore = 0;
                this.drawMythLimitMythDrawTimes = 0;
            }
        }

    }

    public int getScoreItemId() {
        return scoreItemId;
    }

    public int getDrawItemId() {
        return drawItemId;
    }

    public int getTokenItem1() {
        return tokenItem1;
    }

    public int getTokenItem2() {
        return tokenItem2;
    }

    public int getTokenItem3() {
        return tokenItem3;
    }

    public int getDrawScore() {
        return drawScore;
    }

    public int getDrawSimpleEnsureSmallestParam() {
        return drawSimpleEnsureSmallestParam;
    }

    public int getDrawSimpleEnsureBiggestParam() {
        return drawSimpleEnsureBiggestParam;
    }

    public int getDrawMythEnsureSmallestParam() {
        return drawMythEnsureSmallestParam;
    }

    public int getDrawMythEnsureBiggestParam() {
        return drawMythEnsureBiggestParam;
    }

    public int getDrawMythFreeTimes() {
        return drawMythFreeTimes;
    }

    public Map<Integer, WitchDrawCombConfig> getCombConfigMap() {
        return combConfigMap;
    }

    public Map<Integer, WitchDrawItemConfig> getDrawItemConfigMap() {
        return drawItemConfigMap;
    }

    public Map<Integer, Integer> getDrawCombWeightMap() {
        return drawCombWeightMap;
    }

    public int getTenDrawUnlockParam() {
        return tenDrawUnlockParam;
    }

    public Map<Integer, Map<Integer, Integer>> getFloatWeightMap() {
        return floatWeightMap;
    }

    public int getDrawMythLimitMythDrawScore() {
        return drawMythLimitMythDrawScore;
    }

    public int getDrawMythLimitMythDrawTimes() {
        return drawMythLimitMythDrawTimes;
    }
}
